package com.leve.control.controller.app;

import com.leve.control.constant.Constants;
import com.leve.control.constant.ErrorCode;
import com.leve.control.service.CuserService;
import com.leve.control.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author whongyu
 * @create by 2019/6/12
 */
@Slf4j
@RestController
@CrossOrigin
@RequestMapping("/api/app/cuser")
@Api(tags = {"app端用户相关接口服务"})
public class AppCuserController {

    @Autowired
    private CuserService cuserService;

    @ApiOperation(value = "app用户登录接口")
    @PostMapping(value = "/login")
    @ResponseBody
    public Result login(@RequestParam String mobile ,@RequestParam String verificationCode){
        log.info(Constants.REQ + ErrorCode.SUCCESS.getCode() + "|api/app/cuser/login|app用户登录接口,mobile={},verificationCode={}: "+ mobile,verificationCode);
        try{
            return cuserService.login(mobile,verificationCode);
        }catch (Exception e){
            log.error(Constants.RES + ErrorCode.E_10001.getCode()+ "|api/app/cuser/login|app用户登录接口", e);
            return new Result(ErrorCode.E_10001);
        }
    }

    @ApiOperation(value = "手机验证码发送接口")
    @PostMapping(value = "/send")
    @ResponseBody
    public Result sendSms(@RequestParam String mobile){
        log.info(Constants.REQ + ErrorCode.SUCCESS.getCode() + "|api/app/cuser/send|手机验证码发送接口,mobile={}: "+mobile);
        try{
            int sms = cuserService.sendSms(mobile);
            return new Result(ErrorCode.SUCCESS,sms);
        }catch (Exception e){
            log.error(Constants.RES + ErrorCode.E_10001.getCode()+ "|api/app/cuser/send|手机验证码发送接口", e);
            return new Result(ErrorCode.E_10001);
        }
    }


}
